package com.gzy.android_douban.ui.me;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.gzy.android_douban.databinding.FragmentTabBinding;

public class TabFragment extends Fragment {
    private static final String ARG_PARAM = "param1";

    // 定义TextView显示的文本和界面的背景色Id变量
    private String message;

    public TabFragment() {
        // Required empty public constructor
    }

    // 创建TabFragment对象，使用setArguments()传递两个参数
    public static TabFragment newInstance(String param) {
        TabFragment fragment = new TabFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM, param);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 获取传递的两个参数的额值
        Bundle bundle = getArguments();
        if (bundle != null) {
            message = bundle.getString(ARG_PARAM);
        }
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // 注册Fragment的布局文件
        FragmentTabBinding binding = FragmentTabBinding.inflate(inflater, container, false);
        // 设置文本和背景色
        if (!message.isEmpty()) {
            binding.tvMessage.setText(message);
        }
        // 返回view
        return binding.getRoot();
    }
}